<?php

namespace App\Http\Requests;
use Validator;
use Illuminate\Foundation\Http\FormRequest;
use Hash;
use Auth;
class PasswordRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }
    public function guize(){
    	Validator::extend ('check_password',function ($attribute,$value,$parameters,$validator){
			return Hash::check ($value,Auth::user ()->password);
		});
	}
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'nickname'=>'required',
			'oldpassword'=>'nullable|check_password',
			'password'=>'nullable|confirmed|between:6,20',
			'password_confirmation'=>'nullable|between:6,20'
        ];
    }
    public function messages ()
	{
		return [
			'oldpassword.check_password'=>'旧密码错误!',
		];
	}
}
